Root users and mysql: `sudo mysql` vs `/root/.my.cnf`

Posted by user67641 on Server Fault See other posts from Server Fault or by user67641
Published on 2011-03-12T21:13:15Z Indexed on 2011/03/13 0:12 UTC
Read the original article Hit count: 448

Filed under:
|
|
|
|

I have a /root/.my.cnf file which stores the mysql root user's password:

[client]
password = "my password"

When I log in as system root and enter mysql, I get a passwordless login:

myuser@local:$ sudo su
root@local:$ mysql
mysql>

But when I try to do the same just using sudo, I get access denied:

myuser@local:$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

How can I get sudo mysql to log me in as the mysql root user, without entering a password?

© Server Fault or respective owner

Related posts about mysql

Related posts about sudo